package com.atguigu.controller;

import com.atguigu.entity.User;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("user")
@Api(tags = "用户服务的相关接口描述")
public class UserController {
    @GetMapping("findAll")
    @ApiOperation(value = "查询所有用户的接口",notes = "描述： 用来查询所有用户信息的接口")
    public Map<String,Object> findAll(){
        Map<String,Object>mp=new HashMap<>();
        mp.put("success","查询所有成功");
        mp.put("state",true);
        return mp;
    }

    /**
     *
     * @return
     * 默认是用参数传参?id=21&name='Jane'
     * path 用路径中的信息传参save/{id}/{name} @PathVariable
     * body post请求体中传参(json数据)@RequestBody
     */
    @PostMapping("save")
    @ApiOperation(value = "保存用户信息",notes = "描述")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id",value = "用户id",dataType = "String",defaultValue = "21",paramType = "path"),
//            @ApiImplicitParam(name = "name",value ="用户姓名",dataType = "String",defaultValue = "Jane",paramType = "path")
//    })
    @ApiResponses({
            @ApiResponse(code=200,message = "保存用户信息成功"),
            @ApiResponse(code=404,message = "请求路径不存在"),
            @ApiResponse(code = 401,message = "当前请求未被授权")
    })
    public Map<String,Object>save(@RequestBody User user){
        System.out.println("id"+user.getId());
        System.out.println("name:"+user.getName());
        Map<String,Object>map=new HashMap<>();
        map.put("success","查询所有成功");
        map.put("state",true);
        return map;
    }
}
